#!/usr/bin/env node
import commander, { action, program } from "commander";
import { version } from '../package.json'
import { prompt } from 'inquirer'
import { checkDir } from "./util";
import { join } from 'path'
import config from "./config";
import { red, green } from 'chalk'
import { exec } from 'child_process'
import { rename } from 'fs'
import choiceTemp from "./service/choiceTemp";
import choiceLanguage from "./service/choiceLanguage";
program
    .version(version, '-v --version')
    .command('init <projectname>')
    .alias('i')
    .description('按模板初始化项目')
    .action(
        async (projectName) => {
            
            checkDir(join(process.cwd(), projectName), projectName);
            const chooseTemplate = await choiceTemp();
            const languageInfo = await choiceLanguage();

            return;
            prompt(config.temptList).then(({ templateInfo: {
                location,
                temptName,
                branchName
            } }) => {
                console.log(green('请确认你选择的模板:\n'), '****', red(temptName))

                // return console.log(green(JSON.stringify(value)))
                // const { url, gitName, val } = result.type;
                // console.log("您选择的模版类型信息如下：" + val);
                // console.log('项目初始化拷贝获取中...');
                // if (!url) {
                //     console.log(red(`${val} 该类型暂不支持...`));
                //     process.exit(1);
                // }
                // exec('git clone ' + url, function (error, stdout, stderr) {
                //     if (error !== null) {
                //         console.log(red(
                //             `clone fail,${error}`
                //         ));
                //         return;
                //     }
                //     rename(gitName, projectName, (err) => {
                //         if (err) {
                //             exec('rm -rf ' + gitName, function (err, out) { });
                //             console.log(red(`The ${projectName} project template already exist`));
                //         } else {
                //             console.log(green(`The ${projectName} project template successfully create(项目模版创建成功)`));
                //         }
                //     });
                // });
            })
        }
    )
program.parse(process.argv)